1. Field of the Invention
The invention relates to a method for managing a program memory and more particularly, to a method for managing an external program memory of a microprocessor.
2. Description of the Prior Art
Intel Corporation generally refers to a microprocessor as an MCS (Micro Computer System) and the MCS-51/52 series microprocessor developed by the Intel Corporation is commonly used in industry. Generally speaking, a microprocessor comprises a small memory and a few I/O ports. Take the MCS-51 microprocessor for example; it comprises a program memory of 4K bytes, a data memory of 128 bytes, and 32 I/O ports. The MCS-52 series microprocessor comprises a program memory of 8K bytes and a data memory of 256bytes. The MCS-51/52 series of microprocessors features an 8-bit CPU. The program memory is a read-only memory (ROM) for storing a program written by a user. The data memory is a random-access memory for storing data temporarily while the CPU executes a program. The capacity of the memory of the MCS-51/52 series microprocessor can be externally expanded to 64K bytes.
An external program memory with capacity of 64K bytes is still not large enough if the user needs to write lengthy code or use a large array table. To solve this problem, the capacity of the external program memory of the microprocessor can be substantially expanded by switching a plurality of memory banks when the user uses the extra pins of the microprocessor as decode lines to set an address for an external program memory with capacity of over 64K bytes. If the external program memory is one memory device with large capacity, the extra pins of the microprocessor can be address lines. If there are several external program memory devices with smaller capacity, the extra pins of the microprocessor can be used to select the memory chips. Because the largest capacity of the external program memory of the microprocessor is 64K bytes, 64k bytes can be taken as a unit (a page) when the microprocessor switches the memory banks. Further, an interrupt vector table is usually stored at a specific address of the external program memory, and the microprocessor searches for the interrupt vector table at the specific address in a current page immediately when an interrupt occurs. Because the microprocessor cannot switch the plurality of memory banks when the interrupt occurs, an error occurs when the microprocessor cannot find the interrupt vector table in the current page. To solve this problem, a common area in each memory bank is reserved for storing the interrupt vector table, interrupt service routines, common program library, and a memory bank switching routine, etc. This ensures that the microprocessor can find the interrupt vector table in the current page (can be any page) and, when the interrupt is served, continue executing the interrupted program.
FIG. 1 is a diagram of an external program memory 12 according to the prior art. The capacity of the external program memory 12 of the MCS-51/52 series microprocessor is expanded to 512K bytes by switching the plurality of memory banks. The external program memory 12 is divided into 8 pages. The capacity of each page is 64K bytes but a common area in each page with certain capacity (ex. 10K bytes)is reserved for storing the interrupt vector table, the interrupt service routines, the common program library, and the memory bank switching routine, etc. For example, when the microprocessor has to execute a program B in page 2 while executing a program A in page 1, it will call the bank switching routine in the common area. The memory bank switching routine stored in the common area will set the page number to 2, then the microprocessor can access the program B in page 2. After executing the program in the page 2, the microprocessor will return to the program A by calling the bank switching routine in the common area, and the memory bank switching routine will switch the page number from 2 to 1, so the microprocessor can return to the address of the program A in page 1 to continue executing the program A. Further, when the interrupt occurs, the microprocessor accesses the interrupt vector table stored in the common area to access and execute the interrupt service routines according to the content of the interrupt vector table. The microprocessor then comes back to the original address of the program to continue executing the interrupted program. The interrupt service routines and the interrupt vector table are stored in the common area of each page, thus, when accessing the interrupt service routines and the interrupt vector table, it is not necessary to switch the pages.
According to the foregoing description, though the largest capacity of the external program memory of the MCS-51/52 series microprocessor is 64K bytes, the external program memory can be further expanded by switching the plurality of memory banks when using the extra pins of the microprocessor as the decode lines to set the address of the external program memory with capacity of over 64K bytes. However, each memory bank has to reserve a certain space for the common area to store the interrupt vector table, the interrupt service routines, the common program library, and the memory bank switching routine, etc. These multiple common areas mean the space of the external program memory is not used efficiently.